//
//  LXHomePluginVC.m
//  APMDemo
//
//  Created by Jack on 2020/7/20.
//  Copyright © 2020 LX. All rights reserved.
//

#import "LXHomePluginVC.h"
#import "LXHomePluginCell.h"

@interface LXHomePluginVC ()<UICollectionViewDataSource,UICollectionViewDelegate>

/** 内容界面 */
@property (nonatomic, strong) UICollectionView *collectionView;

@end

static  NSString *LXHomePluginCellIdentifier = @"LXHomePluginCellIdentifier";

@implementation LXHomePluginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.collectionView];
}

#pragma mark - UICollectionDataSoucre
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    NSInteger row = 4;
    return row;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    LXHomePluginCell *cell = nil;
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:LXHomePluginCellIdentifier
                                                     forIndexPath:indexPath];
    cell.titleLabel.text = @"日志";
    cell.iconImageView.image = [UIImage imageNamed:@"log"];
    return cell;
}

#pragma mark ---- UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout*)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CGSize size = CGSizeZero;
    size = CGSizeMake([UIScreen mainScreen].bounds.size.width / 4.0, 80);
    
    return size;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                        layout:(UICollectionViewLayout*)collectionViewLayout
        insetForSectionAtIndex:(NSInteger)section{
    
    UIEdgeInsets insets = UIEdgeInsetsZero;
    
    return insets;
}


- (CGFloat)collectionView:(UICollectionView *)collectionView
                   layout:(UICollectionViewLayout*)collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    CGFloat space = 0.0;
    if (section == 0 || section == 2) {
        space = 15;
    }
   
    return space;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView
                   layout:(UICollectionViewLayout*)collectionViewLayout
minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    CGFloat space = 0.0;
    if (section == 2) {
        space = 15;
    }
    
    return space;
}

#pragma mark ---- UICollectionViewDelegate
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    
   
    
    return YES;
}

// 点击高亮
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
}

// 选中某item
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSInteger section = indexPath.section;
    NSInteger row     =indexPath.row;
}

#pragma mark - Getter
- (UICollectionView *)collectionView{
    
    if (_collectionView == nil) {
        
        //1.初始化layout
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        //设置collectionView滚动方向
        [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
       
        UICollectionView *clv = [[UICollectionView alloc] initWithFrame:self.view.bounds
                                                  collectionViewLayout:layout];
        clv.backgroundColor   = [UIColor whiteColor];
        clv.alwaysBounceVertical  = YES;
        clv.delegate          = self;
        clv.dataSource        = self;
        clv.showsVerticalScrollIndicator   = NO;
        clv.showsHorizontalScrollIndicator = NO;
        
        [clv registerClass:[LXHomePluginCell class] forCellWithReuseIdentifier:LXHomePluginCellIdentifier];
       
        _collectionView = clv;
    }
    
    return _collectionView;
}

@end
